home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / src / kant-generator-04-c / Kant ƒ / Shell ƒ / about MSG.c next >
Encoding:
C/C++ Source or Header  |  1994-11-23  |  5.9 KB  |  201 lines  |  [TEXT/MMCC]

  1. #include "about MSG.h"
  2. #include "styled text.h"
  3.  
  4. /*-----------------------------------------------------------------------------------*/
  5. /* internal stuff for about MSG.c                                                    */
  6.  
  7. static    void SetupTheAboutMSGWindow(WindowDataHandle theData);
  8. static    void ShutdownTheAboutMSGWindow(WindowDataHandle theData);
  9. static    void OpenTheMSGWindow(WindowDataHandle theData);
  10. static    void DrawTheAboutMSGWindow(WindowDataHandle theData);
  11. static    void DoTheMSGThing(WindowDataHandle theData);
  12. static    void AboutMSGEventLoop(WindowDataHandle theData);
  13.  
  14. static    PicHandle    gAboutPict=0L;
  15. static    CharHandle    gAboutText=0L;
  16. static    StylHandle    gAboutStyle=0L;
  17.  
  18. static    Ptr            gOffscreenBitMap=0L;
  19. static    GrafPort    gOffscreenGrafPort;
  20. static    GrafPtr        gOffscreenGrafPtr=0L;
  21.  
  22. #define MAX_OFFSCREEN_LINES    5
  23. #define kOffscreenWidth        130
  24. #define kOffscreenHeight    ((MAX_OFFSCREEN_LINES*12)+1)
  25. #define RIGHT_SLOP            13
  26. #define TOP_SLOP            29
  27.  
  28. #define    kAboutTextID        150
  29.  
  30. short AboutMSGBoxDispatch(WindowDataHandle theData, short theMessage, unsigned long misc)
  31. {
  32.     switch (theMessage)    /* see graphics.h for list of messages*/
  33.     {
  34.         case kUpdate:
  35.             DrawTheAboutMSGWindow(theData);
  36.             return kSuccess;
  37.         case kOpen:
  38.             OpenTheMSGWindow(theData);
  39.             return kSuccess;
  40.         case kStartup:
  41.             SetupTheAboutMSGWindow(theData);
  42.             return kSuccess;
  43.         case kShutdown:
  44.             ShutdownTheAboutMSGWindow(theData);
  45.             return kSuccess;
  46.         case kChangeDepth:
  47.             gAboutPict=ReleaseThePict(gAboutPict);
  48.             return kSuccess;
  49.     }
  50.     
  51.     return kFailure;        /* for all other messages, defer to default processing */
  52. }
  53.  
  54. void SetupTheAboutMSGWindow(WindowDataHandle theData)
  55. {
  56.     long            offRowBytes, sizeOfOff;
  57.     
  58.     (**theData).windowWidth=324;
  59.     (**theData).windowHeight=199;
  60.     (**theData).windowType=plainDBox;
  61.     (**theData).windowTitle[0]=0x00;        /* null title, never shown */
  62.     (**theData).hasCloseBox=FALSE;
  63.     (**theData).maxDepth=8;
  64.     gAboutText=(CharHandle)GetResource('TEXT', kAboutTextID);
  65.     gAboutStyle=(StylHandle)GetResource('styl', kAboutTextID);
  66.  
  67.     gOffscreenGrafPtr=&gOffscreenGrafPort;
  68.     OpenPort(&gOffscreenGrafPort);    /* make a new port */
  69.     
  70.     /* calculate the size of the offscreen bitmap from the boundsrect */
  71.     offRowBytes=(((**theData).windowWidth+15)>>4)<<1;
  72.     sizeOfOff=(long)((**theData).windowHeight)*offRowBytes;
  73.     
  74.     gOffscreenBitMap=NewPtr(sizeOfOff);        /* allocate space for bitmap */
  75.     if (gOffscreenBitMap==0L)                /* abort if unsuccessful */
  76.         Debugger();
  77.     
  78.     gOffscreenGrafPort.portBits.baseAddr=gOffscreenBitMap;    /* --> our bitmap */
  79.     gOffscreenGrafPort.portBits.rowBytes=offRowBytes;        /* bitmap size */
  80.     SetRect(&gOffscreenGrafPort.portBits.bounds, 0, 0, kOffscreenWidth, kOffscreenHeight);
  81.     gOffscreenGrafPort.portRect=gOffscreenGrafPort.portBits.bounds;
  82.     
  83.     SetPort(gOffscreenGrafPtr);
  84. }
  85.  
  86. void ShutdownTheAboutMSGWindow(WindowDataHandle theData)
  87. {
  88.     gAboutPict=ReleaseThePict(gAboutPict);
  89.     if (gOffscreenBitMap!=0L)
  90.     {
  91.         DisposePtr(gOffscreenBitMap);
  92.         ClosePort(&gOffscreenGrafPort);
  93.     }
  94. }
  95.  
  96. void OpenTheMSGWindow(WindowDataHandle theData)
  97. {
  98.     UpdateTheWindow((ExtendedWindowDataHandle)theData);
  99.     AboutMSGEventLoop(theData);
  100. }
  101.  
  102. void AboutMSGEventLoop(WindowDataHandle theData)
  103. {
  104.     GrafPtr            oldPort;
  105.     GrafPtr            curPort;
  106.     short            startLine, numLines;
  107.     short            i;
  108.     Rect            sourceRect, destRect;
  109.     Rect            mirrorSourceRect, mirrorDestRect;
  110.     Rect            newSourceRect, newDestRect;
  111.     long            dummy;
  112.     RgnHandle        scrollRgn;
  113.     Rect            ovalRect;
  114.     Boolean            notDoneYet;
  115.     
  116.     GetPort(&oldPort);
  117.     SetPort(curPort=GetWindowPtr(theData));
  118.     startLine=0;
  119.     numLines=CountLines(gAboutText, gAboutStyle, kCenter, srcXor, gOffscreenGrafPort.portRect);
  120.     SetRect(&sourceRect, curPort->portRect.right-RIGHT_SLOP-kOffscreenWidth,
  121.         TOP_SLOP, curPort->portRect.right-RIGHT_SLOP,
  122.         (curPort->portRect.bottom-curPort->portRect.top)/2);
  123.     OffsetRect(&sourceRect, 0, 1);
  124.     destRect=sourceRect;
  125.     OffsetRect(&destRect, 0, -1);
  126.     mirrorSourceRect=sourceRect;
  127.     mirrorSourceRect.top=sourceRect.bottom-1;
  128.     mirrorSourceRect.bottom=sourceRect.bottom-sourceRect.top+mirrorSourceRect.top;
  129.     mirrorDestRect=mirrorSourceRect;
  130.     OffsetRect(&mirrorDestRect, 0, 1);
  131.     newDestRect=sourceRect;
  132.     newDestRect.top=newDestRect.bottom-1;
  133.     SetRect(&ovalRect, 173, 28, 315, 171);
  134.     scrollRgn=NewRgn();
  135.     OpenRgn();
  136.         FrameOval(&ovalRect);
  137.     CloseRgn(scrollRgn);
  138.     notDoneYet=TRUE;
  139.     
  140.     while (notDoneYet)
  141.     {
  142.         SetPort(gOffscreenGrafPtr);
  143.         FillRect(&(gOffscreenGrafPtr->portRect), &qd.black);
  144.         DrawThePartialText(gAboutText, gAboutStyle, kCenter, srcXor, gOffscreenGrafPort.portRect,
  145.             startLine, startLine+MAX_OFFSCREEN_LINES+1);
  146.         SetPort(curPort);
  147.         
  148.         newSourceRect.top=newSourceRect.left=0;
  149.         newSourceRect.right=kOffscreenWidth;
  150.         newSourceRect.bottom=1;
  151.         for (i=0; ((i<kOffscreenHeight) && ((notDoneYet=(!Button()))==TRUE)); i++)
  152.         {
  153.             CopyBits(&(curPort->portBits), &(curPort->portBits), &sourceRect, &destRect, 0,
  154.                 scrollRgn);
  155.             CopyBits(&(curPort->portBits), &(curPort->portBits), &mirrorSourceRect,
  156.                 &mirrorDestRect, 0, scrollRgn);
  157.             CopyBits(&(gOffscreenGrafPort.portBits), &(curPort->portBits), &newSourceRect,
  158.                 &newDestRect, 0, 0L);
  159.             newSourceRect.top++;
  160.             newSourceRect.bottom++;
  161.             Delay(7, &dummy);
  162.         }
  163.         
  164.         startLine+=MAX_OFFSCREEN_LINES;
  165.         if (startLine>numLines)
  166.             startLine=0;
  167.     }
  168.     
  169.     DisposeRgn(scrollRgn);
  170.     SetPort(oldPort);
  171.     FlushEvents(mouseDown+mouseUp, 0);
  172.     
  173.     CloseTheWindow((ExtendedWindowDataHandle)theData);
  174. }
  175.  
  176. void DrawTheAboutMSGWindow(WindowDataHandle theData)
  177. {
  178.     short            h, w, i;
  179.     Rect            sourceRect, destRect;
  180.     GrafPtr            curPort;
  181.     
  182.     gAboutPict=DrawThePicture(gAboutPict, ((**theData).windowDepth>2) ? 128 : 129, 0, 0);
  183.     if (gAboutPict==0L)
  184.         return;
  185.     
  186.     h=(**gAboutPict).picFrame.bottom-(**gAboutPict).picFrame.top;
  187.     w=(**gAboutPict).picFrame.right-(**gAboutPict).picFrame.left;
  188.     GetPort(&curPort);
  189.     
  190.     SetRect(&sourceRect, 0, 0, w, 1);
  191.     SetRect(&destRect, 0, 2*h-2, w, 2*h-1);
  192.     for (i=0; i<h; i++)
  193.     {
  194.         CopyBits(&(curPort->portBits), &(curPort->portBits), &sourceRect, &destRect, 0, 0L);
  195.         sourceRect.top++;
  196.         sourceRect.bottom++;
  197.         destRect.top--;
  198.         destRect.bottom--;
  199.     }
  200. }
  201.